package com.hejing.URL编程;

import java.net.MalformedURLException;
import java.net.URL;

/**
 * ClassName: URLTest
 * Package: com.hejing.URL编程
 * Description:
 *
 * @Author: HeJing
 * @Create: 2023-06-02 22:48
 * @Version: 1.0
 */
public class URLTest {
    public static void main(String[] args) {

        String str = "http://192.168.32.132:8080/examples/abc.jpg?name=Tom";
        try {
            URL url = new URL(str);
            System.out.println(url.getProtocol());  // http
            System.out.println(url.getHost());      // 192.168.32.132
            System.out.println(url.getPort());      // 8080
            System.out.println(url.getPath());      // /examples/abc.jpg
            System.out.println(url.getFile());      // /examples/abc.jpg?name=Tom
            System.out.println(url.getQuery());     // name=Tom

        } catch (MalformedURLException e) {
            e.printStackTrace();
        }

    }
}






















